export enum ResponsetCode {
  SUCCESS = 200,
  FAILURE = 201,
}
export enum ResponseStatus {
  SUCCESS = "success",
  FAILURE = "failure",
}

export class WebResult {
  time: Date;
  code: ResponsetCode;
  status: ResponseStatus;
  type?: ResponseStatus;
  message: string;
  data: any;

  constructor(
    code: ResponsetCode,
    status: ResponseStatus,
    type?: ResponseStatus,
    message: string = undefined,
    data: any = undefined,
  ) {
    this.time = new Date();
    this.code = code;
    this.status = status;
    this.type = type;
    this.message = message;
    this.data = data;
  }

  static success(
    data: any = undefined,
    message: string = ResponseStatus.SUCCESS,
  ) {
    return new WebResult(
      ResponsetCode.SUCCESS,
      ResponseStatus.SUCCESS,
      ResponseStatus.SUCCESS,
      message,
      data,
    );
  }

  static failure(
    data: any = undefined,
    message: string = ResponseStatus.FAILURE,
  ) {
    return new WebResult(
      ResponsetCode.FAILURE,
      ResponseStatus.FAILURE,
      ResponseStatus.FAILURE,
      message,
      data,
    );
  }
}
